// Canvas class for drawing
//

#ifndef __CANVAS_H__
#define __CANVAS_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "Common/Types.h"

// Params:
//  canvas      is the pointer of output/or refered canvas
//  l,t,r,b     is the left-top/right-bottom x,y coords of rectangle (l,t)-(r,b)

/////////////////////////////////////////////////////////////////////////////
// Canvas class

typedef struct 
{
/* read only */
	UInt8*	pData;			// pointer to the memory where drawing rendered
	UInt16	Width;			// width in pixels, of canvas
	UInt16	Height;			// height in pixels, of canvas
	long	BytesPerRow;	// bytes of memory to use per row, length to next row
	UInt8	Type;			// 0: this an invalid canvas
							// 1: this a memory canvas  (from allocating)
                            // 2: this a mapping canvas (from other buffer/canvas)
	UInt8	ColorSpace;     // 0: RGB555
                            // 1: RGB565
                            // 2: RGB888
                            // 3: Indexed
                            // 3: YUV2
    UInt16  Left;           // clipping area in pixels for all drawing
    UInt16  Top;
    UInt16  Right;
    UInt16  Bottom;
}	TCanvas;

/* Create a canvas object from memory allocating internally */
int  g_CreateCanvas(TCanvas *canvas, int width, int height);

/* Create a canvas object from other continuous buffer */
int  g_DefineCanvas(TCanvas *canvas, char *buff, int width, int height, int bytesPerRow);

/* Create a canvas object from other canvas, drawing may affect both */
int  g_CloneCanvas(TCanvas *canvas, const TCanvas *parent, int l, int t, int r, int b);

/* Destroy a canvas */
/* NOTE: destroy a parent canvas and still use its clone will cause disaster!
		 need to implement a 'reference mechanism' later - OB */
void g_DestroyCanvas(TCanvas *canvas);

/* Perform a bit block transfer (blit) from a canvas to another */
void g_BltCanvas(TCanvas *dest, int x, int y, const TCanvas *src, int l, int t, int r, int b);

/* Copy a canvas to another (i.e. g_BltCanvas full src to dest's 0,0) */
void g_CopyCanvas(TCanvas *dest, const TCanvas *src);

/* Double a canvas on the fly to another */
void g_DblCanvas(TCanvas *dest, const TCanvas *src);

/* Copy a canvas to another w/ YUV transform */
void g_CopyCanvas_YUV(TCanvas *dest, const TCanvas *src);

/* Clear a canvas */
void g_ClearCanvas(TCanvas *dest);

/* Clear a YUV canvas */
void g_ClearCanvas_YUV(TCanvas *dest);

/* Set a clipping area to a canvas */
void g_SetClip(TCanvas *canvas, int l, int t, int r, int b);

/* Get the clipping area of a canvas */
void g_GetClip(TCanvas *canvas, int *l, int *t, int *r, int *b);

/* Modify the clipping area of a canvas by offset */
void g_ModifyClip(TCanvas *canvas, int l, int t, int r, int b);

/* Rest the clipping area of a canvas to default (aka full canvas area) */
void g_ResetClip(TCanvas *canvas);

#ifdef _BF533

#define FIELD1_VB_START		1
#define FIELD1_VB_END  		23
#define FIELD1_AV_START		24
#define FIELD1_AV_END  		263
#define FIELD2_VB_START		264
#define FIELD2_VB_END  		285
#define FIELD2_AV_START		286
#define FIELD2_AV_END  		585
#define HB_LENGTH		268

#define	BF54X_UPGRADE

#ifndef BF54X_UPGRADE
#define RGB_WIDTH      		720
#define RGB_HEIGHT     		480
#else
#define RGB_WIDTH      		600
#define RGB_HEIGHT     		360
#endif
#define YCBCR_WIDTH    		1716
#define YCBCR_HEIGHT   		525

void g_CopyCanvas_YUV_BF533(TCanvas *dest, const TCanvas *src);
void g_CopyCanvas_YUV_BF533_part(TCanvas *dest, const TCanvas *src,TRect rect);

void g_ClearCanvas_YUV_BF533(TCanvas *dest);
#endif

#ifdef __cplusplus
}
#endif

#endif	// __CANVAS_H__
